package com.javasoft.controller.YZX;

import com.javasoft.entity.WJC.StudentAnswer;
import com.javasoft.service.YZX._interface.PaperStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/paper-storage")
public class PaperStorageController {

    @Autowired
    private PaperStorageService paperStorageService;

    /**
     * 添加学生答题记录到数据库。
     *
     * @param studentAnswer 学生答题记录对象
     * @return 成功或失败的状态信息
     */
    @PostMapping("/add")
    public ResponseEntity<String> add(@RequestBody StudentAnswer studentAnswer) {
        try {
            boolean result = paperStorageService.add(studentAnswer);
            if (result) {
                return ResponseEntity.ok("Record added successfully.");
            } else {
                return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to add record.");
            }
        } catch (Exception e) {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("An error occurred: " + e.getMessage());
        }
    }
}